package com.lu.controller;

import com.lu.pojo.Shop;
import com.lu.service.ShopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.List;

@Controller
@RequestMapping("shop")
public class ShopController {
    @Autowired
    private ShopService shopService;
    @RequestMapping(value = "/getAll",method = RequestMethod.GET)
    public String getUser(Model model){
        List<Shop> shops = shopService.getShop ( );
        model.addAttribute ( "shops",shops );
        return "shoplist";
    }
    @RequestMapping(value = "findShopBySid",method = RequestMethod.GET)
    public String findShop(Integer sid,Model model){
        Shop shop = shopService.findShopById ( sid );
        model.addAttribute ( "Shop",shop );
        return "findShop";
    }

    @RequestMapping(value = "updateShop",method = RequestMethod.POST)
    public String update(Shop shop){

        int i = shopService.updateShop(shop);
        System.out.println (shop.getName () );

        return "redirect:/getAll";
    }
    @RequestMapping(value = "/delete",method = RequestMethod.GET)
    public String del(Integer sid){
        System.out.println (sid );

        int i = shopService.del ( sid );

        return "redirect:getAll";
    }
    @RequestMapping(value = "/addShop",method = RequestMethod.POST)
    public String add(Shop shop){
        System.out.println (shop );
        shopService.add ( shop );

        return "redirect:/getAll";
    }

}
